'use strict';

const Controller = require('egg').Controller;
const api = require('../../config/api');

class PublicationController extends Controller {
  async index() {
    const { ctx } = this;
    let name = 'journals';
    if (ctx.url === '/books') {
      name = 'books';
    } else if (ctx.url === '/patents') {
      name = 'patents';
    }
    let res = {};
    switch (name) {
      case 'journals': {
        // 请求 /Article/getArticleList
        res = await ctx.curl(`${api.basicUrl}/Article/getArticleList`, {
          method: 'GET',
          contentType: 'json',
          dataType: 'json',
          data: {
            page: 1,
            pagesize: 10,
          },
        });
        break;
      }
      case 'books': {
        res = await ctx.curl(`${api.basicUrl}/Book/getBookList`, {
          method: 'GET',
          contentType: 'json',
          dataType: 'json',
          data: {
            page: 1,
            pagesize: 10,
          },
        })
        break;
      }
      case 'patents': {
        res = await ctx.curl(`${api.basicUrl}/Patent/getPatentList`, {
          method: 'GET',
          contentType: 'json',
          dataType: 'json',
          data: {
            page: 1,
            pagesize: 10,
          },
        });
        break;
      }
      default: break;
    }
    await ctx.render('publication.html', {
      parentTemplate: 'news_layout.html',
      name,
      pageData: res.data,
    });
  }
}

module.exports = PublicationController;
